package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ServiceAreas;
import com.ruoyi.system.service.IServiceAreasService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务区域Controller
 * 
 * @author ruoyi
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/system/ServiceAreas")
public class ServiceAreasController extends BaseController
{
    @Autowired
    private IServiceAreasService serviceAreasService;

    /**
     * 查询服务区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceAreas:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceAreas serviceAreas)
    {
        startPage();
        List<ServiceAreas> list = serviceAreasService.selectServiceAreasList(serviceAreas);
        return getDataTable(list);
    }

    /**
     * 导出服务区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceAreas:export')")
    @Log(title = "服务区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceAreas serviceAreas)
    {
        List<ServiceAreas> list = serviceAreasService.selectServiceAreasList(serviceAreas);
        ExcelUtil<ServiceAreas> util = new ExcelUtil<ServiceAreas>(ServiceAreas.class);
        util.exportExcel(response, list, "服务区域数据");
    }

    /**
     * 获取服务区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceAreas:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(serviceAreasService.selectServiceAreasByAreaId(areaId));
    }

    /**
     * 新增服务区域
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceAreas:add')")
    @Log(title = "服务区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceAreas serviceAreas)
    {
        return toAjax(serviceAreasService.insertServiceAreas(serviceAreas));
    }

    /**
     * 修改服务区域
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceAreas:edit')")
    @Log(title = "服务区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceAreas serviceAreas)
    {
        return toAjax(serviceAreasService.updateServiceAreas(serviceAreas));
    }

    /**
     * 删除服务区域
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceAreas:remove')")
    @Log(title = "服务区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(serviceAreasService.deleteServiceAreasByAreaIds(areaIds));
    }
}
